package zhizhemodi.tech.short_term_bwork.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import zhizhemodi.tech.short_term_bwork.entity.PlanAndProgram;
import zhizhemodi.tech.short_term_bwork.mapper.PlanAndProgramMapper;

@Service
public class PlanAndProgramService {
    
    @Autowired
    PlanAndProgramMapper planAndProgramMapper;

    @Resource
    ProgramFileListService programFileListService;

    /**
     * 通过计划编号获取节目
     * @param planId
     * @return
     */
    public List<PlanAndProgram> getPlanAndProgramByPlanId(Integer planId) {
        QueryWrapper<PlanAndProgram> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("plan_id", planId);
        return planAndProgramMapper.selectList(queryWrapper);
    }

    /**
     * 通过节目Id删除项目
     * @param programId
     */
    public void deleteByProgramId(Integer programId) {
        QueryWrapper<PlanAndProgram> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("program_id", programId);
        planAndProgramMapper.delete(queryWrapper);
    }

    /**
     * 添加项目
     * @param planAndPrograms
     */
    public void addPlanAndProgramList(List<PlanAndProgram> planAndPrograms) {
        for(PlanAndProgram planAndProgram : planAndPrograms) {
            planAndProgramMapper.insert(planAndProgram);
        }
    }
}
